﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CommonUtility;
using Model;
using System.Web.Script.Serialization;
using BLL;
using DAL;

namespace WebApplication
{
    public partial class LogInf : BasePage
    {
        const string FunID = "FA06";
        protected void Page_Load(object sender, EventArgs e)
        {
            string action = Common.ToString(Request["Action"]);
            switch (action)
            {
                case "GetData":
                    Response.Write(LoadData());
                    Response.End();
                    break;
                case "LoadFunName":
                    Response.Write(LoadFunName());
                    Response.End();
                    break;
                case "LoadActionID":
                    Response.Write(LoadAction());
                    Response.End(); ;
                    break;
                default:
                    break;
            }
            if (!IsPostBack && string.IsNullOrEmpty(action))
            {
                bllPermission Perm = new bllPermission(oUser.UserID, FunID);
                hdPermission.Value = new JavaScriptSerializer().Serialize(Perm);
            }
        }

        /// <summary>
        /// 获取方法
        /// </summary>
        /// <returns></returns>
        private string LoadAction()
        {
            IList<ActionInfo> list = DAL.Action.GetList("");
            return new JavaScriptSerializer().Serialize(list);
        }

        /// <summary>
        /// 获取方法
        /// </summary>
        /// <returns></returns>
        private string LoadFunName()
        {
            IList<FunctionInfo> list = Function.GetList("");
            return new JavaScriptSerializer().Serialize(list);
        }

        /// <summary>
        /// 获取数据
        /// </summary>
        /// <returns></returns>
        private string LoadData()
        {
            string result = "";
            string strFromTime = Common.ToString(Request["fromtime"]).Replace("'", "''");
            string strToTime = Common.ToString(Request["totime"]).Replace("'", "''");
            string strWho = Common.ToString(Request["who"]).Replace("'", "''");
            string strFunID = Common.ToString(Request["funid"]).Replace("'", "''");
            string strActionName = Common.ToString(Request["actionName"]).Replace("'", "''");

            int total = 0;

            try
            {
                IList<LogInfo> list = bllLog.GetList(strFromTime, strToTime, strWho, strFunID, strActionName, Common.ToString(Request["sortname"]) + " " + Common.ToString(Request["sortorder"]), Common.ToInt32(Request["page"]), Common.ToInt32(Request["pagesize"]), ref total);

                string json = new JavaScriptSerializer().Serialize(list);
                result = @"{""Rows"":" + json + @",""Total"":""" + total + @"""}";
            }
            catch (System.Exception ex)
            {
                result = "ERR";
            }

            return result;
        }
    }
}